/**
 * <copyright>
 * Copyrigth 2007 Aurelien Moreau
 *
 * This file is part of ProcessShop.
 *
 * ProcessShop is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * ProcessShop is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with ProcessShop; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 * </copyright>
 *
 * $Id$
 */
package net.yienyien.process.bpd.impl;

import java.util.Collection;

import net.yienyien.process.bpd.BPDComponent;
import net.yienyien.process.bpd.BPDModel;
import net.yienyien.process.bpd.BPDObject;
import net.yienyien.process.bpd.BpdPackage;
import net.yienyien.process.bpd.ControlFlowRelation;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;
import org.eclipse.emf.ecore.util.EObjectResolvingEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>BPD Component</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link net.yienyien.process.bpd.impl.BPDComponentImpl#getEntry <em>Entry</em>}</li>
 *   <li>{@link net.yienyien.process.bpd.impl.BPDComponentImpl#getExit <em>Exit</em>}</li>
 *   <li>{@link net.yienyien.process.bpd.impl.BPDComponentImpl#getSource <em>Source</em>}</li>
 *   <li>{@link net.yienyien.process.bpd.impl.BPDComponentImpl#getSink <em>Sink</em>}</li>
 *   <li>{@link net.yienyien.process.bpd.impl.BPDComponentImpl#getObjects <em>Objects</em>}</li>
 *   <li>{@link net.yienyien.process.bpd.impl.BPDComponentImpl#getRelations <em>Relations</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class BPDComponentImpl extends TaskImpl implements BPDComponent {
	/**
	 * The cached value of the '{@link #getEntry() <em>Entry</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEntry()
	 * @generated
	 * @ordered
	 */
	protected BPDObject entry;

	/**
	 * The cached value of the '{@link #getExit() <em>Exit</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getExit()
	 * @generated
	 * @ordered
	 */
	protected BPDObject exit;

	/**
	 * The cached value of the '{@link #getSource() <em>Source</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSource()
	 * @generated
	 * @ordered
	 */
	protected BPDObject source;

	/**
	 * The cached value of the '{@link #getSink() <em>Sink</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSink()
	 * @generated
	 * @ordered
	 */
	protected BPDObject sink;

	/**
	 * The cached value of the '{@link #getObjects() <em>Objects</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getObjects()
	 * @generated
	 * @ordered
	 */
	protected EList<BPDObject> objects;

	/**
	 * The cached value of the '{@link #getRelations() <em>Relations</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getRelations()
	 * @generated
	 * @ordered
	 */
	protected EList<ControlFlowRelation> relations;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected BPDComponentImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return BpdPackage.Literals.BPD_COMPONENT;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public BPDObject getEntry() {
		if (entry != null && entry.eIsProxy()) {
			InternalEObject oldEntry = (InternalEObject)entry;
			entry = (BPDObject)eResolveProxy(oldEntry);
			if (entry != oldEntry) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, BpdPackage.BPD_COMPONENT__ENTRY, oldEntry, entry));
			}
		}
		return entry;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public BPDObject basicGetEntry() {
		return entry;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setEntry(BPDObject newEntry) {
		BPDObject oldEntry = entry;
		entry = newEntry;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, BpdPackage.BPD_COMPONENT__ENTRY, oldEntry, entry));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public BPDObject getExit() {
		if (exit != null && exit.eIsProxy()) {
			InternalEObject oldExit = (InternalEObject)exit;
			exit = (BPDObject)eResolveProxy(oldExit);
			if (exit != oldExit) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, BpdPackage.BPD_COMPONENT__EXIT, oldExit, exit));
			}
		}
		return exit;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public BPDObject basicGetExit() {
		return exit;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setExit(BPDObject newExit) {
		BPDObject oldExit = exit;
		exit = newExit;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, BpdPackage.BPD_COMPONENT__EXIT, oldExit, exit));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public BPDObject getSource() {
		if (source != null && source.eIsProxy()) {
			InternalEObject oldSource = (InternalEObject)source;
			source = (BPDObject)eResolveProxy(oldSource);
			if (source != oldSource) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, BpdPackage.BPD_COMPONENT__SOURCE, oldSource, source));
			}
		}
		return source;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public BPDObject basicGetSource() {
		return source;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setSource(BPDObject newSource) {
		BPDObject oldSource = source;
		source = newSource;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, BpdPackage.BPD_COMPONENT__SOURCE, oldSource, source));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public BPDObject getSink() {
		if (sink != null && sink.eIsProxy()) {
			InternalEObject oldSink = (InternalEObject)sink;
			sink = (BPDObject)eResolveProxy(oldSink);
			if (sink != oldSink) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, BpdPackage.BPD_COMPONENT__SINK, oldSink, sink));
			}
		}
		return sink;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public BPDObject basicGetSink() {
		return sink;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setSink(BPDObject newSink) {
		BPDObject oldSink = sink;
		sink = newSink;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, BpdPackage.BPD_COMPONENT__SINK, oldSink, sink));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<BPDObject> getObjects() {
		if (objects == null) {
			objects = new EObjectResolvingEList<BPDObject>(BPDObject.class, this, BpdPackage.BPD_COMPONENT__OBJECTS);
		}
		return objects;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<ControlFlowRelation> getRelations() {
		if (relations == null) {
			relations = new EObjectResolvingEList<ControlFlowRelation>(ControlFlowRelation.class, this, BpdPackage.BPD_COMPONENT__RELATIONS);
		}
		return relations;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case BpdPackage.BPD_COMPONENT__ENTRY:
				if (resolve) return getEntry();
				return basicGetEntry();
			case BpdPackage.BPD_COMPONENT__EXIT:
				if (resolve) return getExit();
				return basicGetExit();
			case BpdPackage.BPD_COMPONENT__SOURCE:
				if (resolve) return getSource();
				return basicGetSource();
			case BpdPackage.BPD_COMPONENT__SINK:
				if (resolve) return getSink();
				return basicGetSink();
			case BpdPackage.BPD_COMPONENT__OBJECTS:
				return getObjects();
			case BpdPackage.BPD_COMPONENT__RELATIONS:
				return getRelations();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case BpdPackage.BPD_COMPONENT__ENTRY:
				setEntry((BPDObject)newValue);
				return;
			case BpdPackage.BPD_COMPONENT__EXIT:
				setExit((BPDObject)newValue);
				return;
			case BpdPackage.BPD_COMPONENT__SOURCE:
				setSource((BPDObject)newValue);
				return;
			case BpdPackage.BPD_COMPONENT__SINK:
				setSink((BPDObject)newValue);
				return;
			case BpdPackage.BPD_COMPONENT__OBJECTS:
				getObjects().clear();
				getObjects().addAll((Collection<? extends BPDObject>)newValue);
				return;
			case BpdPackage.BPD_COMPONENT__RELATIONS:
				getRelations().clear();
				getRelations().addAll((Collection<? extends ControlFlowRelation>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case BpdPackage.BPD_COMPONENT__ENTRY:
				setEntry((BPDObject)null);
				return;
			case BpdPackage.BPD_COMPONENT__EXIT:
				setExit((BPDObject)null);
				return;
			case BpdPackage.BPD_COMPONENT__SOURCE:
				setSource((BPDObject)null);
				return;
			case BpdPackage.BPD_COMPONENT__SINK:
				setSink((BPDObject)null);
				return;
			case BpdPackage.BPD_COMPONENT__OBJECTS:
				getObjects().clear();
				return;
			case BpdPackage.BPD_COMPONENT__RELATIONS:
				getRelations().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case BpdPackage.BPD_COMPONENT__ENTRY:
				return entry != null;
			case BpdPackage.BPD_COMPONENT__EXIT:
				return exit != null;
			case BpdPackage.BPD_COMPONENT__SOURCE:
				return source != null;
			case BpdPackage.BPD_COMPONENT__SINK:
				return sink != null;
			case BpdPackage.BPD_COMPONENT__OBJECTS:
				return objects != null && !objects.isEmpty();
			case BpdPackage.BPD_COMPONENT__RELATIONS:
				return relations != null && !relations.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	@Override
	public boolean isComposite() {
		return true;
	}

} //BPDComponentImpl
